-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New rule: prefer-readonly-type-alias #255
Conversation
Note: this rule is using typescript-eslint/typescript-eslint#3658 |
31fa3dc
to
f5ec4a3
Compare
May want to wait for typescript-eslint/typescript-eslint#1758 to be fixed too. If upstream takes too long to resolve the issues/PRs, we can copy-paste in the relevant code to our repo in the meantime. |
What would be the use-case for checking that types are not readonly? I like the dualism vs checking for readonly but I think we might introduce functionality that is not needed to encourage functional paradigms. My concern is mainly that it might make it more difficult to refactor/change things in the future as we may need to continuously support this functionality whether it is used or not. I think it would be enough to support emulation of a |
I did probably set this rule up to a little more that it needs to. The intent was so that it could not only check for readonly types like Thus the following use-case would be allowed (with some configuration, not by default): type MyType = {
foo: string;
bar: string;
readonly baz: string;
}
type ReadonlyMyType = {
readonly foo: string;
readonly bar: string;
readonly baz: string;
} The rule would be able to flag |
7e70479
to
1d41819
Compare
1d41819
to
aa3d4cf
Compare
Closed in favor of #259 |
Note: The rule might want a new name as it can also require aliases to be mutable.
By default, this rule requires that all type aliases are deeply readonly unless prefixed with
Mutable
.I can however be configured to work the other way around and require that all type aliases are not deeply readonly unless prefixed with
Readonly
.It's also possible to have a mixture of both these configure and to use other patterns to determine readonly vs mutable.